package com.event.controller;


import com.event.pojo.StudySrc;
import com.event.service.PostCommentService;
import com.event.service.PostService;
import com.event.service.StudySrcService;
import com.event.service.UserService;
import com.event.util.GetIp;
import com.event.util.dateTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;


@Controller
public class JumpController {

    @Autowired
    PostCommentService postCommentService;
    @Autowired
    PostService postService;
    @Autowired
    StudySrcService studySrcService;
    @Autowired
    UserService userService;
    @RequestMapping("/manageEvent2021")
    public String manage(Model model){
            return "html/index";
        }
    @RequestMapping("/desktop")
    public String desktop(Model model, HttpSession session, HttpServletRequest request){
        dateTime dateTime = new dateTime();
        GetIp getIp = new GetIp(request);
        session.setAttribute("ip",getIp.getIpAddress());
        session.setAttribute("postCount",postService.selectPost(null).size());
        session.setAttribute("commentCount",postCommentService.selectPostComment(null).size());
        session.setAttribute("userCount",userService.selectUser(null).size());
        session.setAttribute("studySrcCount",studySrcService.selectStudySrc(null).size());
        session.setAttribute("dateTime",dateTime.getTime());
        return "html/welcome";
    }
    @RequestMapping("/updateStudySrc")
    public  String updateStudySrc(Model model, StudySrc studySrc){
         model.addAttribute("studySrc",studySrc);
        return "html/updateStudySrc";
    }

}
